<template>
  <el-dialog
    title="修改"
    :visible="show"
    :close-on-press-escape="false"
    :append-to-body="true"
    width="30%"
    top="20%"
    @close="close"
    center>
    <div class="edit-menu-dialog-box">
      <div class="el-input-box">
        <el-input size="medium" v-model="tagName" placeholder="请输入分类名"/>
      </div>
    </div>
    <span slot="footer" class="add-menu-dialog-footer">
      <el-button type="primary" size="medium" @click="commit">修 改</el-button>
    </span>
  </el-dialog>
</template>

<script>
import Api from "@/utils/api.js";

export default {
  props: ["show", 'item'],

  watch: {
    show(newV, oldV) {
      if(newV){
        this.tagId = this.item.tagId
        this.tagName = this.item.tagName
      }
    } 
  },

  data(){
    return{
      tagId:'',
      tagName:'',
    }
  },

  methods:{
    close(){
      this.$emit('close')
    },

    commit(){
      // 请求接口
      this.$axios.post(Api.BLOG_TAG_EDIT, {
        tagId: this.tagId, 
        tagName : this.tagName,
        orderNum : this.item.orderNum
      }).then( _ =>{
        this.$emit('closeAndEdit', {tagId: this.tagId, tagName : this.tagName})
      }).catch(res =>{
        this.$message.warning(res.message);
      })
    },
  }
}
</script>

<style lang="less" scoped>
@import '@/assets/css/index.less';

.edit-menu-dialog-box{
  .el-input-box{
    margin-bottom: 10px;
  }
}

// 添加菜单弹框
.add-menu-dialog-footer{
  
  .el-button{
      width: 200px;
  }
}
</style>
